<template>
  <div>
    <!-- 运输端 -->
    <el-col :xs="24" :sm="24" :md="12" :lg="24">
      <el-card class="update-log" style="margin-top: 20px">
        <div slot="header" class="clearfix">
          <span>运输信息登记</span>
        </div>
        <div class="body">
          <el-col :xs="24" :sm="24" :md="12" :lg="8">
            <div style="display:flex;align-items: center;justify-content: center;margin-bottom: 20px">
              <img
                src="@/assets/images/saoyisao.png"
                alt="donate"
                width="100px"
                @click="goUrl"
              />
            </div>
            <div style="display: flex;justify-content: center;color: #777;font-size: 13px">点击扫码</div>
          </el-col>
<!--          {{erwm}}-->
          <el-col :xs="24" :sm="24" :md="12" :lg="16">
          <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="120px">
            <el-col>
              <el-col :lg="12">
                <el-form-item label="生产企业名称">
                  {{formData.manufacturer}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="医院名称">
                  {{formData.hospitalName}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="药品名称">
                  {{formData.goodsname}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="批号">
                  {{ formData.batchcode }}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="标示时间">
                  {{ formData.ufFlagtime }}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="放射性活度">
                  {{ formData.ufGoodsrat }}MBq
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="数量">
                  {{ formData.num }}
                </el-form-item>
              </el-col>
            </el-col>

            <el-col :lg="12">
              <el-form-item label="运输单位">
                <el-input v-model="formData.transportUnit" placeholder="请输入运输单位" ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="12">
              <el-form-item label="车辆信息">
                <el-input v-model="formData.vehicleInfo" placeholder="请输入车辆信息" ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="12">
              <el-form-item label="驾驶员信息">
                <el-input v-model="formData.driverInfo" placeholder="请输入驾驶员信息" ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="12">
              <el-form-item label="联系方式">
                <el-input v-model="formData.drivercontact" placeholder="请输入驾驶员联系方式" type="number"></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="12">
              <el-form-item label="起运时间">
                <el-date-picker v-model="formData.startDatetime" format="yyyy-MM-dd HH:mm" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                                :default-time="'06:00:00'" :style="{width: '100%'}" placeholder="请选择起运时间" clearable></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="12">
              <el-form-item label="预计到货时间">
                <el-date-picker v-model="formData.endDatetime" format="yyyy-MM-dd HH:mm" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                                :default-time="'06:00:00'" :style="{width: '100%'}" placeholder="请选择到达时间" clearable></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="24">
              <el-form-item size="large">
                <el-button type="primary" style="float: right" @click="submitForm">提交</el-button>
              </el-form-item>
            </el-col>
          </el-form>
          </el-col>
        </div>
      </el-card>
    </el-col>

  </div>
</template>

<script>

import {getProduceAndTransInfo, getProduceAndTransInfoErp, updateZsdt, updateZsdtErp} from "@/api/flow/produceAndTrans";

export default {
  data(){
    return {
      qcode:'',//二维码id

      erwm:'二维码数据',
      formData:  {
        amount:null,
        batchcode:null,
        bsdate:null,
        createTime:null,
        dedrate:null,
        driverInfo:null,
        drivercontact:null,//驾驶员联系方式
        endDatetime:null,
        execnum:null,
        goodid:null,
        goodscode:null,
        goodsname:null,
        goodsspec:null,
        hospitalName:null,
        hospitalShr:null,
        manufacturer:null,
        num:null,
        oldprice:null,
        orderId:null,
        piclink:null,
        place:null,
        price:null,
        produceDate:null,
        qcode:null,
        qualityReport:null,
        radioActivity:null,
        shipper:null,
        startDatetime:null,
        transportUnit:null,
        unit:null,
        validDate:null,
        vehicleInfo:null,
        ysSituation:null,
      },
      rules: {
        field102: [{
          required: true,
          message: '请输入生产企业名称',
          trigger: 'blur'
        }],
        field103: [{
          required: true,
          message: '请输入单行文本',
          trigger: 'blur'
        }],
      },
    }
  },
  created() {
    let querys= this.$route.query
    console.log('上级传参',querys)
    if(querys.qrresult){
      this.qcode=querys.qrresult
    }
    //根据二维码id获取信息
    this.getInfo()
  },
  methods:{
    //二维码功能跳转
    goUrl(){
      window.location.href='//996315.com/api/scan/?redirect_uri='+window.location.origin+'/order/from/transportfrom'
    },
    getInfo(){
      this.loading = true;
      getProduceAndTransInfoErp(this.qcode).then(res =>{
        if(res.code == 200 ){
          if(res.data.length > 0){
            console.log('二维码内容',res.data[0])
            this.formData = res.data[0];
          }
        }else {
          this.$message.error(res.msg)
        }
        this.loading = false;
      })
    },
    //提交
    submitForm(){
      this.loading = true;
      //获取当前用户的id，赋值update_by字段
      if(this.$store.state.user.userId){
        this.formData.updateBy = this.$store.state.user.userId;
      }
      //图片路径同步
      console.log('提交信息',this.formData)
      updateZsdtErp(this.formData).then(res =>{
        if(res.code == 200){
          this.$message.success('更新成功')
          this.reset()
        }else {
          this.$message.error(res.msg)
        }
        this.loading = false;
      })
    },
    //formData重置
    reset(){
      this.formData={
        amount:null,
        batchcode:null,
        bsdate:null,
        createTime:null,
        dedrate:null,
        driverInfo:null,
        endDatetime:null,
        execnum:null,
        goodid:null,
        goodscode:null,
        goodsname:null,
        goodsspec:null,
        hospitalName:null,
        hospitalShr:null,
        manufacturer:null,
        num:null,
        oldprice:null,
        orderId:null,
        piclink:null,
        place:null,
        price:null,
        produceDate:null,
        qcode:null,
        qualityReport:null,
        radioActivity:null,
        shipper:null,
        startDatetime:null,
        transportUnit:null,
        unit:null,
        validDate:null,
        vehicleInfo:null,
        ysSituation:null,
      }
    }

  }

}
</script>

<style>

</style>
